﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AgileDashboard.Entities;
using AutoMapper;
using System.Configuration;

namespace PlanningPokerMVC.Models
{
    public class PlanningPokerViewModel
    {

        public PlanningPokerViewModel()
        {
            WorkItems = new List<WorkItemViewModel>();

        }

        public PlanningPokerViewModel(List<WorkItem> workItems)
        {



            foreach (WorkItem workItem in workItems)
                WorkItems.Add(Convert(workItem));



        }

        public void Add(WorkItem workItem)
        {
            if (WorkItems == null)
                WorkItems = new List<WorkItemViewModel>();

            WorkItems.Add(Convert(workItem));

        }

        public List<WorkItemViewModel> WorkItems { get; set; }


        public WorkItemViewModel Convert(WorkItem workItem)
        {
            WorkItemViewModel vm = new WorkItemViewModel();
            vm.Id = workItem.Id;
            vm.Title = workItem.Title;
            vm.Description = workItem.Description;
            vm.IterationPath = workItem.IterationPath;
            string url = ConfigurationManager.AppSettings["TfsWorkItemUrl"] + workItem.Id;
            vm.WorkItemUrl = HttpUtility.UrlDecode(url);


            vm.WinningVote = workItem.WinningVote;
            vm.VoteCount = workItem.VoteCount;


            return vm;

        }
    }


    public class WorkItemViewModel
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public string IterationPath { get; set; }

        private string _workItemUrl;

        public string WorkItemUrl
        {
            get 
            { 
                
                return _workItemUrl; 
            }
            set { _workItemUrl = value; }
        }

        public int? WinningVote { get; set; }
        public int VoteCount { get; set; }




    }


}